// 引入expres
const express = require('express');
// 引入路由
const router = new express.Router();
// 引入 db.js 模块
// 定义连接字符串
// 定义数据库名称
// 定义集合
// 引入 fs 模块
// const fs = require('fs');
// 引入 jwt 模块
// const jwt = require('jsonwebtoken');
// 定义加密字符串
// const secret = 'abcdefghijklmnopqrstuvwxyz';
const myDate = new Date();

/* 轮播图路径 */
const lunboStr = [
  { img: 'https://img.alicdn.com/tfs/TB1RhCuBlr0gK0jSZFnXXbRRXXa-520-280.jpg_q90_.webp' },
  { img: 'https://aecpm.alicdn.com/simba/img/TB1JNHwKFXXXXafXVXXSutbFXXX.jpg' },
  { img: 'https://aecpm.alicdn.com/simba/img/TB183NQapLM8KJjSZFBSutJHVXa.jpg' }
];

/* 模拟新闻列表 */
const newsList = [
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-09T04:05:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://k.sinaimg.cn/n/news/crawl/117/w550h367/20200402/2f84-irpunai5068956.jpg/w200h134f1t0l50q90c55.jpg"
  },
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-09T04:05:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://k.sinaimg.cn/n/news/crawl/117/w550h367/20200402/2f84-irpunai5068956.jpg/w200h134f1t0l50q90c55.jpg"
  },
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-09T04:05:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://k.sinaimg.cn/n/news/crawl/117/w550h367/20200402/2f84-irpunai5068956.jpg/w200h134f1t0l50q90c55.jpg"
  },
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-09T04:05:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://k.sinaimg.cn/n/news/crawl/117/w550h367/20200402/2f84-irpunai5068956.jpg/w200h134f1t0l50q90c55.jpg"
  },
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-09T04:05:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://k.sinaimg.cn/n/news/crawl/117/w550h367/20200402/2f84-irpunai5068956.jpg/w200h134f1t0l50q90c55.jpg"
  },
  {
    id: 1,
    title: `[联讯今日财经] 80后股市奇才，自创"主力吸筹战法"，引大量媒介报道！`,
    add_time: "2020-04-09T10:25:40,0002",
    zhaiyao: "座右铭：赢家不害怕当数，因为赢家本来就是少数!",
    click: 1,
    img_url: "https://s3.pfp.sina.net/ea/ad/2/4/447a2cc1850126c3b165f0446b910be0.jpeg"
  },
  {
    id: 2, title: "大陆军机绕台后，台媒又曝“美舰通过台湾海峡，大陆导弹护卫舰伴随监控”",
    add_time: "2020-04-10T22:11:34.0002",
    zhaiyao: "刚刚过去的24小时，台海局势真热闹！",
    click: 2,
    img_url: "https://n.sinaimg.cn/spider2020410/174/w568h406/20200410/4e4e-iryninx4674220.png"
  }
];
/* 模拟子新闻详情 */
const newSon = [
  {id: 1, htmlSrc: "http://www.jstdtncj.com/xxl04/118/?SET_A=PDPS000000056287&SET_B=3521017&SET_C=4197363&SET_D=d1343833-2a3d-4451-b56d-6d5d16fdd9ec&SET_E=3233036&SET_F=1"},
  {id: 2, htmlSrc: "https://news.sina.cn/gj/2020-04-10/detail-iirczymi5605571.d.html?cre=tianyi&mod=wnews&loc=14&r=0&rfunc=57&tj=cxvertical_wap_wnews&tr=167&vt=4&pos=3"}
];

/* 图文分享头部数据 */
const imgcategory_header = [
  {
    id: 1,
    title: "家居生活"
  },
  {
    id: 2,
    title: "摄影设计"
  },
  {
    id: 3,
    title: "明星美女"
  },
  {
    id: 4,
    title: "空间设计"
  },
  {
    id: 5,
    title: "乡间微拍"
  },
  {
    id: 6,
    title: "异地风光"
  }
];
/* 图文分享——家居生活 */
const imgcategory_jjsh = [
  {
    id: 1,
    imgSrc: "http://img3.selfimg.com.cn/andinormal/2019/12/27/1577433503_dhIdof.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20191104/news_10gg988591ec6eed.html",
    picture_captions: "爱上意大利",
    picture_pape: `意大利人可能是世界上最自由不羁的一群人！他们热爱生活、无拘无束，说起话来常常伴随着欢快的手势，仿佛随时就要跳起舞来。这是意大利人的生活日常，也是意大利设计的重要基因。如今，意大利设计穿越时间和国度，在中国遇见了一批年轻拥趸。吸引这些“80后”“90后”的并非家具的名牌或大师光环，而是显而易见的先锋、趣味，甚至一点儿疯狂，这正是中国年轻人向往的与众不同。一件件意大利家具就这样被带回了家，也带回了年轻人的自我表达和生活主张。`
  },
  {
    id: 2,
    imgSrc: "http://img1.selfimg.com.cn/andinormal/2019/12/27/1577432644_0E98iD.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20191212/news_13g2a00c506ce90b.html",
    picture_captions: "半梦半醒",
    picture_pape: `
    酒，百乐之长！千百年来，这种取自粮食或水果的精华，带着不同颜色与气味的液体，不知拨动着古今中外多少灵魂创意者的心弦，又促生了多少巨作的诞生。与酿酒一样，对于饮酒者来说，时机同样重要，喝到恰到好处，半醉半醒之间，感性来袭而理智又尚未完全褪去之际，是敞开心扉、灵感闪现的高光时刻。本期，我们与艺术、设计、人文圈内的老友们摆起酒局，谈起各自的饮酒高光时刻。 对于他们来说，每一次饮酒未必有目的可言，却是从创作压力中逃得半刻闲的灵感解药。`
  },
  
  {
    id: 3,
    imgSrc: "http://img3.selfimg.com.cn/andinormal/2019/12/27/1577433508_Jukngz.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20190705/news_1211c3e85afe5186.html",
    picture_captions: "持续前行",
    picture_pape: `今年的米兰设计周处处充满“善意”，对可持续设计的关注已从呼声发展至实际行动。一线设计师义不容辞呈现出实践成果，品牌投入大量资本研发、生产，策展机构向公众普及知识、促发讨论，整个设计行业整齐地联动在一起。米兰，当之无愧的世界设计之都！`
  },
  {
    id: 4,
    imgSrc: "http://img3.selfimg.com.cn/andinormal/2019/12/27/1577433349_DTAGKO.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20191025/news_104gc971cc9562a7.html",
    picture_captions: "艺术叩门",
    picture_pape: `起初，可能只是一种颜色、一个形状、一根线条，让他们眼前一亮、心生喜悦，便叩开了艺术的大门，开启了之后的漫漫收藏之路。诚然艺术有价、收藏有术，但为自的家和办公室挑选艺术品时，除了“价”与“术”,还需对艺术、 空间、生活、自我的综合理解，那几乎是一次对艺术的“再创作”！来源于生活的艺术最终又回到生活中去，这正是收藏的乐趣，更是艺术的能量！`
  },
  {
    id: 5,
    imgSrc: "http://img1.selfimg.com.cn/andinormal/2019/12/27/1577433400_DsazvC.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20191018/news_1734986badf8a220.html",
    picture_captions: "魔幻雾都",
    picture_pape: `在中国，再没有一个城市像重庆一般充满了热气腾腾的魔幻现实主义。山城的地理条件让它自带3D模式; 两江交汇的码头文化让它充满粗犷的生命力，大家聚拢一处推杯换盏、江湖义气，用聚集的人情对抗自然的不测风浪。 同时。它又坐拥四川美院这种现实悲悯土壤里开出的艺术之花, 让它在翻滚的“红油”中又有了茶样的“汤底”。而现在，还有了一群人，希望用带着生活温度和地域印迹的设计来为这座通常“大行不顾细谨”的城市优化更新，让这里的日子在有滋有味之外也更有型有款起来。只有当你全身心投入它的至情至性，你方能真的触摸它、感受它，然后衷心说一句：哦，勒是雾都！`
  },
  {
    id: 6,
    imgSrc: "http://img3.selfimg.com.cn/andinormal/2019/12/27/1577433463_uNqXEE.jpg",
    newUrl: "http://m.adstyle.com.cn/stories/20190716/news_1311df71976593a2.html",
    picture_captions: "米兰特快",
    picture_pape: `更多家具品牌集中在米兰时装周上发布新品，从色彩、材质到款式，以及由此所带来的生活方式、家居观念的改变……家居流行趋势在此一目了然！`
  }
];


/* 评论详情数据 */
const comments = [
  {id: "30", user_name: "匿名用户", add_time: "2020-04-11T22:19:24,0002", content: "内容30"},
  {id: "29", user_name: "匿名用户", add_time: "2020-04-11T20:19:24,0002", content: "内容29"},
  {id: "28", user_name: "匿名用户", add_time: "2020-04-11T18:19:20,0002", content: "内容28"},
  {id: "27", user_name: "匿名用户", add_time: "2020-04-11T17:19:16,0002", content: "内容27"},
  {id: "26", user_name: "匿名用户", add_time: "2020-04-11T16:19:12,0002", content: "内容26"},
  {id: "25", user_name: "匿名用户", add_time: "2020-04-11T15:19:10,0002", content: "内容25"},
  {id: "24", user_name: "匿名用户", add_time: "2020-04-11T14:19:00,0002", content: "内容24"},
  {id: "23", user_name: "匿名用户", add_time: "2020-04-11T10:19:28,0002", content: "内容23"},
  {id: "22", user_name: "匿名用户", add_time: "2020-04-11T09:19:28,0002", content: "内容22"},
  {id: "21", user_name: "匿名用户", add_time: "2020-04-11T08:19:28,0002", content: "内容21"},
  
  {id: "20", user_name: "匿名用户", add_time: "2020-04-11T22:19:24,0002",  content: "内容20"},
  {id: "19", user_name: "匿名用户", add_time: "2020-04-11T20:19:24,0002",  content: "内容19"},
  {id: "18", user_name: "匿名用户", add_time: "2020-04-11T18:19:20,0002",  content: "内容18"},
  {id: "17", user_name: "匿名用户", add_time: "2020-04-11T17:19:16,0002",  content: "内容17"},
  {id: "16", user_name: "匿名用户", add_time: "2020-04-11T16:19:12,0002",  content: "内容16"},
  {id: "15", user_name: "匿名用户", add_time: "2020-04-11T15:19:10,0002",  content: "内容15"},
  {id: "14", user_name: "匿名用户", add_time: "2020-04-11T14:19:00,0002",  content: "内容14"},
  {id: "13", user_name: "匿名用户", add_time: "2020-04-11T10:19:28,0002",  content: "内容13"},
  {id: "12", user_name: "匿名用户", add_time: "2020-04-11T09:19:28,0002",  content: "内容12"},
  {id: "11", user_name: "匿名用户", add_time: "2020-04-11T08:19:28,0002",  content: "内容11"},

  {id: "10", user_name: "匿名用户", add_time: "2020-04-11T22:19:24,0002",  content: "内容10"},
  {id: "9" , user_name: "匿名用户", add_time: "2020-04-11T20:19:24,0002",  content: "内容9"},
  {id: "8" , user_name: "匿名用户", add_time: "2020-04-11T18:19:20,0002",  content: "内容8"},
  {id: "7" , user_name: "匿名用户", add_time: "2020-04-11T17:19:16,0002",  content: "内容7"},
  {id: "6" , user_name: "匿名用户", add_time: "2020-04-11T16:19:12,0002",  content: "内容6"},
  {id: "5" , user_name: "匿名用户", add_time: "2020-04-11T15:19:10,0002",  content: "内容5"},
  {id: "4" , user_name: "匿名用户", add_time: "2020-04-11T14:19:00,0002",  content: "内容4"},
  {id: "3" , user_name: "匿名用户", add_time: "2020-04-11T10:19:28,0002",  content: "内容3"},
  {id: "2" , user_name: "匿名用户", add_time: "2020-04-11T09:19:28,0002",  content: "内容2"},
  {id: "1" , user_name: "匿名用户", add_time: "2020-04-11T08:19:28,0002",  content: "内容1"},
];

/* 商品列表数据 */
const goodsData = [
  {id: 1, title: "韩版大码短袖t恤2020",sell_price: 99, market_price: 79, stock_quantity: 20, img_url: "//img.alicdn.com/bao/uploaded/i3/3449622634/O1CN01cRUZH61VKPpNoaBJP_!!0-item_pic.jpg_10000x340Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://gd4.alicdn.com/imgextra/i3/60711540/O1CN01QRyEfo1NFMX7MFrP3_!!60711540.jpg_400x400.jpg_.webp"},
    {img: "https://gd3.alicdn.com/imgextra/i3/60711540/O1CN01NQAw2E1NFMX9CPRgw_!!60711540.jpg_400x400.jpg_.webp"},
    {img: "https://gd3.alicdn.com/imgextra/i3/60711540/O1CN01IorRCd1NFMXDw0ABS_!!60711540.jpg_400x400.jpg_.webp"}
  ]},
  {id: 2, title: "洋气T恤网纱半身裙",sell_price: 349, market_price: 199, stock_quantity: 30, img_url: "//img.alicdn.com/bao/uploaded/i2/1710141938/O1CN01rWPqKN1QBeA8Nuikq_!!0-item_pic.jpg_10000x340Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://gd2.alicdn.com/imgextra/i1/2003913666/O1CN01wDThAR1cx4ZK90seY_!!2003913666-0-pixelsss.jpg_400x400.jpg_.webp"},
    {img: "https://gd2.alicdn.com/imgextra/i2/2003913666/O1CN01ZGs1Mm1cx4ZMVHNO8_!!2003913666.jpg_400x400.jpg_.webp"},
    {img: "https://gd1.alicdn.com/imgextra/i1/2003913666/O1CN01jZxJ7u1cx4ZJklLcF_!!2003913666.jpg_400x400.jpg_.webp"}
  ]},
  {id: 3, title: "独角兽的眼泪星月项链",sell_price: 188, market_price: 128, stock_quantity: 8, img_url: "//img.alicdn.com/bao/uploaded/i1/3234882899/O1CN01B2KVHW1XHmlx6pT9W_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://gd2.alicdn.com/imgextra/i3/751437331/O1CN01037NYX241e6uU7L04_!!751437331.jpg_400x400.jpg_.webp"},
    {img: "https://gd2.alicdn.com/imgextra/i2/751437331/O1CN01bkQVym241e9WG9oxN_!!751437331.jpg_400x400.jpg_.webp"},
    {img: "https://gd4.alicdn.com/imgextra/i4/751437331/O1CN01TXxNXA241e6x6VRAM_!!751437331.jpg_400x400.jpg_.webp"}
  ]},
  {id: 4, title: "2020年法式白色连衣裙",sell_price: 99, market_price: 88, stock_quantity: 30, img_url: "//img.alicdn.com/bao/uploaded/i1/4048570022/O1CN01nOllkM1C27IxAUmbW_!!4048570022-0-lubanu-s.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i4/827894246/O1CN01Do3Zr11hEiHPsZ14A_!!0-item_pic.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i1/827894246/O1CN01C1TO0y1hEiHZqZOyX_!!827894246.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i2/827894246/O1CN01AGfYEY1hEiHZ1ejVB_!!827894246.jpg_430x430q90.jpg"}
  ]},
  {id: 5, title: "韩版纯棉性感吊带背心",sell_price: 66, market_price: 38, stock_quantity: 10, img_url: "//img.alicdn.com/bao/uploaded/i1/3162413522/O1CN01F6HmKr1bt7XClBzWN_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i3/2217148345/O1CN01F1fsSp2BW3gdAluPk_!!0-item_pic.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2217148345/TB2YYjro0nJ8KJjSszdXXaxuFXa_!!2217148345.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i1/2217148345/TB2k30Ro8DH8KJjSszcXXbDTFXa_!!2217148345.jpg_430x430q90.jpg"}
  ]},
  {id: 6, title: "创意20s防摔20pro手机壳",sell_price: 28, market_price: 19.9, stock_quantity: 999, img_url: "//img.alicdn.com/bao/uploaded/i4/2201189100617/O1CN015Pds9R1GQcxo6uI8d_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i4/2077099208/O1CN01aoUwYB2HtJVmRVM7P_!!2077099208.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2077099208/O1CN01Ubzw9J2HtJVmlzDHL_!!2077099208.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2077099208/O1CN01oUYoMN2HtJVlGpHkz_!!2077099208.jpg_430x430q90.jpg"}
  ]},
  {id: 3, title: "独角兽的眼泪星月项链",sell_price: 188, market_price: 128, stock_quantity: 8, img_url: "//img.alicdn.com/bao/uploaded/i1/3234882899/O1CN01B2KVHW1XHmlx6pT9W_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://gd2.alicdn.com/imgextra/i3/751437331/O1CN01037NYX241e6uU7L04_!!751437331.jpg_400x400.jpg_.webp"},
    {img: "https://gd2.alicdn.com/imgextra/i2/751437331/O1CN01bkQVym241e9WG9oxN_!!751437331.jpg_400x400.jpg_.webp"},
    {img: "https://gd4.alicdn.com/imgextra/i4/751437331/O1CN01TXxNXA241e6x6VRAM_!!751437331.jpg_400x400.jpg_.webp"}
  ]},
  {id: 4, title: "2020年法式白色连衣裙",sell_price: 99, market_price: 88, stock_quantity: 30, img_url: "//img.alicdn.com/bao/uploaded/i1/4048570022/O1CN01nOllkM1C27IxAUmbW_!!4048570022-0-lubanu-s.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i4/827894246/O1CN01Do3Zr11hEiHPsZ14A_!!0-item_pic.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i1/827894246/O1CN01C1TO0y1hEiHZqZOyX_!!827894246.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i2/827894246/O1CN01AGfYEY1hEiHZ1ejVB_!!827894246.jpg_430x430q90.jpg"}
  ]},
  {id: 6, title: "创意20s防摔20pro手机壳",sell_price: 28, market_price: 19.9, stock_quantity: 999, img_url: "//img.alicdn.com/bao/uploaded/i4/2201189100617/O1CN015Pds9R1GQcxo6uI8d_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i4/2077099208/O1CN01BJ3AP82HtJVmRX25Z_!!0-item_pic.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2077099208/O1CN01Ubzw9J2HtJVmlzDHL_!!2077099208.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2077099208/O1CN01oUYoMN2HtJVlGpHkz_!!2077099208.jpg_430x430q90.jpg"}
  ]},
  {id: 2, title: "洋气T恤网纱半身裙",sell_price: 349, market_price: 199, stock_quantity: 30, img_url: "//img.alicdn.com/bao/uploaded/i2/1710141938/O1CN01rWPqKN1QBeA8Nuikq_!!0-item_pic.jpg_10000x340Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://gd2.alicdn.com/imgextra/i1/2003913666/O1CN01wDThAR1cx4ZK90seY_!!2003913666-0-pixelsss.jpg_400x400.jpg_.webp"},
    {img: "https://gd2.alicdn.com/imgextra/i2/2003913666/O1CN01ZGs1Mm1cx4ZMVHNO8_!!2003913666.jpg_400x400.jpg_.webp"},
    {img: "https://gd1.alicdn.com/imgextra/i1/2003913666/O1CN01jZxJ7u1cx4ZJklLcF_!!2003913666.jpg_400x400.jpg_.webp"}
  ]},
  {id: 5, title: "韩版纯棉性感吊带背心",sell_price: 66, market_price: 38, stock_quantity: 10, img_url: "//img.alicdn.com/bao/uploaded/i1/3162413522/O1CN01F6HmKr1bt7XClBzWN_!!0-item_pic.jpg_336x336Q50s50.jpg_.webp",
   img_lunbo: [
    {img: "https://img.alicdn.com/imgextra/i3/2217148345/O1CN01F1fsSp2BW3gdAluPk_!!0-item_pic.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i3/2217148345/TB2YYjro0nJ8KJjSszdXXaxuFXa_!!2217148345.jpg_430x430q90.jpg"},
    {img: "https://img.alicdn.com/imgextra/i1/2217148345/TB2k30Ro8DH8KJjSszcXXbDTFXa_!!2217148345.jpg_430x430q90.jpg"}
  ]}
];
/* 商品列表——各商品数据 */
const goodsInfo = [
  {
    id: 1,
    title: "韩版大码短袖t恤2020",
    add_time: "2020-04-19T19:34:55.0002",
    goods_no: "SD3973042341",
    stock_quantity: 20,
    market_price: 99,
    sell_price: 79
  },
  {
    id: 2,
    title: "独角兽的眼泪星月项链",
    add_time: "2020-03-30T19:50:55.0002",
    goods_no: "SD3345642342",
    stock_quantity: 30,
    market_price: 188,
    sell_price: 108
  },
  {
    id: 3,
    title: "2020年法式白色连衣裙",
    add_time: "2020-03-30T19:34:55.0002",
    goods_no: "SD3345642343",
    stock_quantity: 8,
    market_price: 128,
    sell_price: 188
  },
  {
    id: 4,
    title: "2020年法式白色连衣裙",
    add_time: "2020-02-30T19:34:55.0002",
    goods_no: "SD3345642344",
    stock_quantity: 30,
    market_price: 38,
    sell_price: 66
  },
  {
    id: 5,
    title: "韩版纯棉性感吊带背心",
    add_time: "2020-02-30T19:36:55.0002",
    goods_no: "SD3345642345",
    stock_quantity: 10,
    market_price: 38,
    sell_price: 66
  },
  {
    id: 6,
    title: "创意20s防摔20pro手机壳",
    add_time: "2020-02-04T19:34:55.0002",
    goods_no: "SD3345642346",
    stock_quantity: 999,
    market_price: 19.9,
    sell_price: 28
  }
];
/* 购物车——商品信息图片等  结束 */






/* 默认 */
router.get('/', function (req, res, next) {
  res.send({ title: '测试中心' });
});

/* 轮播图 —— 首页 */
router.get('/getlunbo/gethomelunbo', (req, res) => {
  // console.log('********************')
  // console.log(req.body)
  res.send(JSON.stringify(lunboStr));
});
/* 轮播图 —— 商品列表 */
router.get('/getlunbo/getthumImages', (req, res) => {
  let temp = goodsData.filter(function(val, index){
    // console.log(val.id);
    return parseInt(val.id) === parseInt(req.query.id);
  });
  // console.log("temp: ", temp[0]);
  res.send(JSON.stringify(temp[0].img_lunbo));
});


/* 新闻 */
router.get('/getnewslist', (req, res) => {
  res.send(JSON.stringify(newsList));
});
/* 子新闻 */
router.get('/getnew', (req, res) => {
  // console.log(req.query.id);
  let temp = newSon.filter(function(val, index){
    // console.log(val.id);
    return parseInt(val.id) === parseInt(req.query.id);
  });
  // console.log("temp: ", temp[0]);
  res.send(JSON.stringify(temp[0]));
});

/* 图文分享 */
router.get('/getimgcategory', (req, res)=>{
  res.send(JSON.stringify(imgcategory_header));
});
/* 图文分享 —— 家居生活 */
router.get('/getimges', (req, res)=>{
  let temp;
  if(req.query.id == 0 || req.query.id == 1){
    temp = imgcategory_jjsh;
  }
  res.send(JSON.stringify(temp));
});

/* 评论详情 */
router.get('/getcomments', (req, res)=>{
  console.log(req.query);
  let temp;
  let num = 10;
  temp = comments.slice((req.query.pageindex-1) * num , (req.query.pageindex-1) * num + 10);
  // temp = comments.slice(0, 10);
  // console.log(temp);
  res.send(JSON.stringify(temp));
});
/* 发表评论 */
router.post('/postcomment/:0', (req, res)=>{
  console.log(req.body);
  let len = comments.length + 1;
  // 获取当前时间
  let myTime = myDate;
  let temp = {id: len, user_name: "匿名用户", add_time: myTime, content: req.body.content};
  comments.unshift(temp);
  res.send(JSON.stringify(temp));
});

/* 商品列表 */
router.get('/getgoodslist', (req, res)=>{
  // console.log(req.query);
  let temp;
  let num = 5;
  
  temp = goodsData.slice((req.query.pageindex-1) * num , (req.query.pageindex-1) * num + num);
  // temp = comments.slice(0, 10);
  // console.log(temp);
  res.send(JSON.stringify(temp));
});
/* 商品列表——商品详情 */
router.get('/goods/getinfo', (req, res)=>{
  let temp = goodsInfo.filter(function(val, index){
    // console.log(val.id);
    return parseInt(val.id) === parseInt(req.query.id);
  });
  // console.log("temp: ", temp[0]);
  res.send(JSON.stringify(temp[0]));
});

/* 购物车列表 */
router.get('/goods/geetshopcarlist', (req, res)=>{
  let ids = req.query.id;
  // console.log(ids);
  // 如果不存在 返回空
  if(ids === undefined){
    res.send(JSON.stringify('null'));
    return;
  }
  // 如果只有一个， 则将 ids 转为 数组
  if(!Array.isArray(ids)){
    ids = [].slice.call(ids);
  }
  // console.log(ids);
  let temp = null;
  let list = ids.map((item, index)=>{
    temp = goodsData.filter((val, index)=>{
      // console.log(val.id);
      return parseInt(val.id) === parseInt(item);
    });
    let obj = {
      id: temp[0].id,
      title: temp[0].title,
      sell_price: temp[0].sell_price,
      thumb_path: temp[0].img_url
    }
    return obj;
  });
  // console.log(list);
  res.send(JSON.stringify(list));
});







// 暴露功能 
module.exports = router;